import {ReactElement} from 'shared/reactSymbols.js'

//不能进行枚举的属性
const RESERVED_PROPS={
    key: true,
    ref: true,
    __self: true,
    __source: true,
};

//是不是有效的ref
function hasValidRef(ref){
    return ref!==undefined
}

//是不是有效的key
function hasValidKey(key){
    return key!==undefined
}

function createElement(type,props,key,ref){
    return {
        $typeof:ReactElement,
        type,
        props,
        key,
        ref,
    }
}

export function jsxDEV(type,config,key){
    let props={}
    let ref,propName
    if(hasValidRef(config.ref)){
        ref=config.ref
    }
    if(hasValidKey(config.key)){
        key=config.key
    }
    for(propName in config){
        if(Object.hasOwnProperty.call(config,propName) &&
            !RESERVED_PROPS.hasOwnProperty(propName)
        ){
            props[propName]=config[propName]
        }
    }
    return createElement(type,props,key,ref)
}